//
//  WPReadingAVCollectionViewCell.m
//  wobingwoyi
//
//  Created by WGP on 2016/12/1.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPReadingAVCollectionViewCell.h"
#import "WPVideoOrAudioModel.h"

@interface WPReadingAVCollectionViewCell ()

@property(nonatomic,strong)UIImageView *bgImageView;
@property(nonatomic,strong)UIImageView *iconImageView;
@property(nonatomic,strong)UILabel *timeLabel;

@end
@implementation WPReadingAVCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    [self bgImageView];
    [self timeLabel];
    [self iconImageView];
}

-(UIImageView *)bgImageView
{
    if (_bgImageView == nil)
    {
        _bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_bg"]];
        _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        _bgImageView.clipsToBounds = YES;
        [self.contentView addSubview:_bgImageView];
        
        [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
    }
    return _bgImageView;
}

-(UIImageView *)iconImageView
{
    if (_iconImageView == nil)
    {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zw_audio_icon"]];
        [self.contentView addSubview:_iconImageView];
        
        [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(5);
            make.bottom.equalTo(self.contentView).offset(-16);
        }];
    }
    return _iconImageView;
}

-(UILabel *)timeLabel
{
    if (_timeLabel == nil)
    {
        _timeLabel = [UILabel new];
        _timeLabel.textAlignment  =NSTextAlignmentRight;
        _timeLabel.text = @"00:04";
        _timeLabel.font = [UIFont systemFontOfSize:12];
        _timeLabel.textColor = RGB_SAME(153);
        [self.contentView addSubview:_timeLabel];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.iconImageView);
            make.right.equalTo(self.contentView).offset(-10);
        }];
    }
    return _timeLabel;
}

-(void)setModel:(WPVideoOrAudioModel *)model
{
    _model = model;
    
    if ([model.type isEqualToString:@"video"])
    {
        self.iconImageView.image = [UIImage imageNamed:@"zw_video_icon"];
        [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:model.imagUrl] placeholderImage:[UIImage imageNamed:@"loadFailed"]];
    }
    else if([model.type isEqualToString:@"audio"])
    {
        self.iconImageView.image = [UIImage imageNamed:@"zw_audio_icon"];
        self.bgImageView.image = [UIImage imageNamed:@"audio_bg"];
    }
    
    self.timeLabel.text = model.multfileTime;
}
@end
